#ifndef _VIDEO_GRAPHICS_H_
#define _VIDEO_GRAPHICS_H_

#include <dpmi.h>
#include <stdio.h>
#include <dpmi.h>
#include <go32.h>
#include <sys/farptr.h>
#include <pc.h>
#include <stdlib.h>
#include <sys/nearptr.h>
#include <math.h>
#include <string.h>

/** @defgroup Video Video 
 * @{
 *
 * Entering/leaving/utility video functions
 */

 // Cores
 #define BLACK 0x00
 #define BRIGHT 0x08
 #define RED 0x04
 #define GREEN 0x02
 #define BLUE 0x01
 #define WHITE 0x07

 #define TOP_BORDER 18
 
 #define CHAR_HEIGHT 16
 #define CHAR_WIDTH 8

#define set_pixel(x, y, color, base) ( *((base) + (y)*HRES + (x)) = (color) )
/*
 * there are two global variables, declared (but not defined) here
 */
extern int HRES;  /**< global variable with the horizontal resolution in pixels */
extern int VRES;  /**< global variable with the vertical resolution in pixels */
#define CHR_H 16 // character height
extern char* video_mem;
extern char* image_buffer;
extern char* image_buffer_original;

/** Enter graphics mode, enabling near pointers and mapping video physical memory
 * to program virtual address.
 *
 * Returns a generic pointer pointing to video memory address or NULL on error. 
 * "mode" specifies the VESA graphics mode to use, and
 * the mapping information is returned through "map".
 *
 * Also initializes two global variables, VRES and HRES,
 */
char * enter_graphics(int mode, __dpmi_meminfo *map);

/** Unmap video memory, disable near pointer and returns to text mode
 */
void leave_graphics(__dpmi_meminfo *map);

/** Draws a pixel of color "color" at screen coordinates x, y at memory address "base"
 */
//void set_pixel2(int x, int y, int color, char *base);
void set_large_pixel(int x, int y, int color, char *base);

/** Returns the pixel color at screen coordinates x, y at memory address "base"
 */
int get_pixel(int x, int y, char *base);

/** Set graphics memory at memory address "base" to "color".
 */
void clear_screen(char color, char *base);
void clear_game_screen(char color, char *base);

void reset_screen(char color, char *base);

/** Draw a line of color "color" between point (xi,yi) and (xf,yf) at memory address "base"
*/
void draw_line(int xi, int yi, int xf, int yf, int color, char *base);

/** Draw a rectangle of color "color" with vertexes (x1,y1),(x2,y1),(x2,y2),(x1,y2) at memory address "base"
 */
void draw_rect(int x1, int y1, int x2, int y2, int color, char *base);

void drawCharAt(char c, int x, int y, int fore_color, int back_color, int char_scale, char *table, char* base);

/** Copia o buffer de imagem "buffer" para o endereço de memória "base".
*/
void swap_buffers(char* buffer, char* base);
void swap_game_buffers(char* buffer, char* base);
/** @} end of video */ 

#endif
